package fragments;

import java.util.List;

import com.evaluity.R;

import logic.Answer;
import views.AnswerAdapter;
import activities.QuestionsList;
import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.webkit.WebView.FindListener;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.ToggleButton;
import android.widget.RadioGroup.LayoutParams;

@SuppressLint("ValidFragment")
public class AnswersListFragment extends Fragment {
	
	List<Answer> answers;
	
	public AnswersListFragment() {
		super();
	}
	
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		
		View layout = inflater.inflate(R.layout.radio_button_group, container, false);
		RadioGroup rbg = (RadioGroup) layout.findViewById(R.id.radioGroup1);
		
		RadioButton rb1 = (RadioButton) rbg.findViewById(R.id.radioButton1);
		RadioButton rb2 = (RadioButton) rbg.findViewById(R.id.radioButton2);
		RadioButton rb3 = (RadioButton) rbg.findViewById(R.id.radioButton3);
		
		rb1.setText(answers.get(0).getText());
		rb1.setChecked(answers.get(0).isSelected());
		rb1.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				QuestionsList ac = ((QuestionsList) getActivity());
				answers.get(0).setSelected(true);
				ac.setSelectedAnswer(answers.get(0));
				ac.toggle();
			}
		});
		
		rb2.setText(answers.get(1).getText());
		rb2.setChecked(answers.get(1).isSelected());
		rb2.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				QuestionsList ac = ((QuestionsList) getActivity());
				answers.get(1).setSelected(true);
				ac.setSelectedAnswer(answers.get(1));
				ac.toggle();
			}
		});
		
		rb3.setText(answers.get(2).getText());
		rb3.setChecked(answers.get(2).isSelected());
		rb3.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				QuestionsList ac = ((QuestionsList) getActivity());
				answers.get(2).setSelected(true);
				ac.setSelectedAnswer(answers.get(2));
				ac.toggle();
			}
		});
		
		return layout;
	}
	
	public AnswersListFragment(Context context) {
		this.answers = QuestionsList.selectedAnswers;
	}	
}
